package com.buss.member.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.jweb.core.bean.ReplyDataMode;
import org.jweb.core.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.buss.common.entity.DictType;
import com.buss.common.service.SysServiceI;
import com.buss.member.entity.GeneralUserEntity;
import com.buss.member.transfer.form.member.MemberRegistForm;
import com.buss.member.transfer.vo.setting.DictTypeVO;
import com.buss.member.util.MemberUtil;


@Controller
@RequestMapping("/setting")
public class SettingController extends BaseController{
	@Autowired
	private SysServiceI sysService;

	@Autowired
	private EhCacheManager ehcacheCacheManager;
	
//	@RequestMapping(value = "/tradeAdvice")
	@ResponseBody
	public ReplyDataMode order(MemberRegistForm saveForm,HttpServletRequest req){
		ReplyDataMode j = new ReplyDataMode();
		
		if(	!MemberUtil.validSMSCode(saveForm.getMphone(), saveForm.getValidCode(), ehcacheCacheManager)){
			j.setSuccess(false);
			return j;
		}
		
		GeneralUserEntity userEntity = (GeneralUserEntity)saveForm.toEntity();
		this.sysService.save(userEntity);
		
		j.setSuccess(true);
		return j;
	}
	
	
	
	/**
	 * 喊单设置数据字典
	 * @param mphone
	 * @param req
	 * @return
	 */
//	@RequestMapping(value = "/notifySettingDict")
	@ResponseBody
	public ReplyDataMode notifySettingDict(HttpServletRequest req){
		ReplyDataMode j = new ReplyDataMode();
		List<DictType> dictTypeList = this.sysService.findDict("custom");
		List<DictTypeVO> dictTypeVOList = new ArrayList<DictTypeVO>();
		for(DictType d : dictTypeList){
			DictTypeVO vo = new DictTypeVO();
			vo.copyEntity(d);
			dictTypeVOList.add(vo);
		}
		j.setSuccess(true);
		j.setData(dictTypeVOList);
		return j;
	}

	
}
